<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('请假申请新增及修改')"/>
    <th:block th:include="include :: businessCSS"/>
    <style>

        .preservationBtn {
            padding: 10px;
            text-align: center;
        }

        .preservationBtn input {
            font-size: 16px;
            background-color: rgb(80, 138, 238);
            color: #fff;
            border: none;
            padding: 5px 30px;
            border-radius: 10px;
            cursor: pointer;
        }

    </style>
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
    <div class="main-content">
        <form class="layui-form head-form">
            <div class="north">
                <!--				<th:block th:include="include :: business_tpl('top')" />-->
                <div class="forminput"></div>
            </div>
            <div class="mid-content">
                <div style="font-weight: 700;font-size:16px;margin-bottom:10px;">子件列表</div>
                <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
            </div>
            <!-- <th:block th:include="include :: pageFooter" /> -->
            <div class="layui-form-item preservationBtn" th:if="${vType} != 3">
                <input type="button" lay-submit lay-filter="btn-add" id="btn-add" value="保存">
            </div>
        </form>
    </div>
</div>

<script type="text/html" id="salesReturnSum">
    <span style="margin-right: 25px;">{{typeof d.salesReturnSum !== 'undefined' && d.salesReturnSum !== null?d.salesReturnSum:''}}</span>
    <i class="layui-icon layui-icon-more getMore"
       onclick="getMore('salesReturnSum',{{d.LAY_TABLE_INDEX}},'入账申请','twc_partnerbookedapply')"
       style="float:right;z-index:999"></i>
</script>

<script type="text/html" id="vKq">
    <span style="margin-right: 25px;">{{typeof d.vKq !== 'undefined' && d.vKq !== null?d.vKq:''}}</span>
    <i class="layui-icon layui-icon-more getMore"
       onclick="getMore('vKq',{{d.LAY_TABLE_INDEX}},'货位编号','tcc_goodsallocation','')"
       style="float:right;z-index:999"></i>
</script>
<script type="text/html" id="vGsBm2">
    <span style="margin-right: 25px;">{{typeof d.vGsBm2 !== 'undefined' && d.vGsBm2 !== null?d.vGsBm2:''}}</span>
    <i class="layui-icon layui-icon-more getMore"
       onclick="getMore('vGsMc',{{d.LAY_TABLE_INDEX}},'赔偿公司','','')"
       style="float:right;z-index:999"></i>
</script>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: businessJS"/>
<th:block th:include="include :: inlineJS"/>

<script th:inline="javascript">
    /*<![CDATA[*/
    var fieldsList = [[${fieldsList}]];
    var fieldsHiddenList = [[${fieldsHiddenList}]];
    var moduleTable = [[${moduleTable}]];
    var enableEdit = [[${enableEdit}]];
    //母件表格基础信息
    var gridColumns = [[${gridColumns}]];
    console.log("fieldsList", fieldsList)
    /*]]>*/
</script>
<script type="text/javascript">
    var vType = [[${vType}]]

    var $, layer, form, laydate, element, table//定义layui模块
        , noTable;//定义全局参数

    layui.use(['laydate', 'form', 'layer', 'jquery', 'util', 'element', 'table'], function () {
        $ = layui.$, layer = layui.layer, form = layui.form, laydate = layui.laydate, util = layui.util, element = layui.element, table = layui.table;
        headcom3()
        var nid = $("#nid").val()
        if (vType == 1) {
            $('#dispose').addClass('canntEdit')
            $('#dispose').attr('disabled', 'disabled');
            // $('select').attr('disabled', 'disabled');
            $('#disposeExplain').addClass('canntEdit')
            $('#disposeExplain').attr('readonly', 'readonly')
        } else if (vType == 2) {
            $('#errorExplain').addClass('canntEdit')
            $('#errorExplain').attr('readonly', 'readonly')
            // $('#dispose').removeClass('canntEdit')
            // $('#dispose').attr('readonly',false)
            // $('#disposeExplain').removeClass('canntEdit')
            // $('#disposeExplain').attr('readonly',false)

        } else {
            $('#dispose').addClass('canntEdit')
            $('#dispose').attr('disabled', true)
            $('#disposeExplain').addClass('canntEdit')
            $('#disposeExplain').attr('readonly', 'readonly')
            $('#errorExplain').addClass('canntEdit')
            $('#errorExplain').attr('readonly', 'readonly')
        }
        form.render("select");
        var bcSm = [
            {width: "45", type: "numbers", fixed: "left"},
            {field: 'sonCode', title: '子件编码', width: 200},
            {field: 'sonName', title: '子件名称', width: 150},
            {field: 'sonPurchaseNum', title: '子件采购总数', width: 150},//采购订单 子件信息
            {field: 'sonNum', title: '子件数量', width: 150},//商品BOM信息
            {field: 'sonPrice', title: '子件单价', width: 150},
            {field: 'sonStoresNum', title: '子件上架数量', width: 150},
        ]

        $.get("/storage/purchasingerror/listbynid?nid=" + nid, function (res) {
            noTable = res.data;

            table.reload('dhtable', {data: res.data, cols: [bcSm]});
            changeselect()
        });

        $.tablelist.init({
            elem: '#dhtable'
            , modalName: "采购报错列表"
            , data: []
            , cols: []
            , page: false
            , height: 'full-' + ($('.north').height() + 140),
        });


        function changeselect(data) {
            if (!data) data = $('#dispose').val()
            if (data == '货物补发') {
                bcSm = [
                    {width: "45", type: "numbers", fixed: "left"},
                    {field: 'sonCode', title: '子件编码', width: 200},
                    {field: 'sonName', title: '子件名称', width: 150},
                    {field: 'sonPurchaseNum', title: '子件采购总数', width: 150},//采购订单 子件信息
                    {field: 'sonNum', title: '子件差额数量', width: 150},//商品BOM信息
                    {field: 'sonPrice', title: '子件单价', width: 150},
                    {field: 'sonStoresNum', title: '子件上架数量', width: 150},
                    {field: 'logisticsChannel1', title: '补发物流渠道', width: 150, edit: 'text'},
                    {field: 'logisticsID1', title: '补发物流单号', width: 150, edit: 'text'},
                    {field: 'logisticsChannel2', title: '补发物流渠道2', width: 150, edit: 'text'},
                    {field: 'logisticsID2', title: '补发物流单号2', width: 150, edit: 'text'},
                    {field: 'logisticsChannel3', title: '补发物流渠道3', width: 150, edit: 'text'},
                    {field: 'logisticsID3', title: '补发物流单号3', width: 150, edit: 'text'},
                ]
            } else if (data == '货款退回') {
                bcSm = [
                    {width: "45", type: "numbers", fixed: "left"},
                    {field: 'sonCode', title: '子件编码', width: 200},
                    {field: 'sonName', title: '子件名称', width: 150},
                    {field: 'sonPurchaseNum', title: '子件采购总数', width: 150},//采购订单 子件信息
                    {field: 'sonNum', title: '子件差额数量', width: 150},//商品BOM信息
                    {field: 'sonPrice', title: '子件单价', width: 150},
                    {field: 'sonStoresNum', title: '子件上架数量', width: 150},
                    {field: 'vJyLx', title: '交易类型', width: 150},
                    {field: 'salesReturnSum', title: '退货金额', width: 150, templet: '#salesReturnSum'},
                ]

            } else if (data == '赔偿') {
                bcSm = [
                    {width: "45", type: "numbers", fixed: "left"},
                    {field: 'sonCode', title: '子件编码', width: 200},
                    {field: 'sonName', title: '子件名称', width: 150},
                    {field: 'sonPurchaseNum', title: '子件采购总数', width: 150},//采购订单 子件信息
                    {field: 'sonNum', title: '子件差额数量', width: 150},//商品BOM信息
                    {field: 'sonPrice', title: '子件单价', width: 150},
                    {field: 'sonStoresNum', title: '子件上架数量', width: 150},
                    {field: 'claimsSum', title: '需赔偿金额', width: 150},
                    {field: 'salesReturnSum', title: '赔偿金额', width: 150, edit: 'text'},
                    {field: 'vGsBm2', title: '理赔公司编码', width: 150, templet: '#vGsBm2'},
                    {field: 'vGsJc2', title: '理赔公司简称', width: 150,}
                ]
            } else if (data == '补入') {
                bcSm = [
                    {width: "45", type: "numbers", fixed: "left"},
                    {field: 'sonCode', title: '子件编码', width: 200},
                    {field: 'sonName', title: '子件名称', width: 150},
                    {field: 'sonPurchaseNum', title: '子件采购总数', width: 150},//采购订单 子件信息
                    {field: 'sonNum', title: '子件差额数量', width: 150},//商品BOM信息
                    {field: 'sonPrice', title: '子件单价', width: 150},
                    {field: 'sonStoresNum', title: '子件上架数量', width: 150},
                    {field: 'productNum', title: '补入数量', width: 150, edit: "text"},
                    {field: 'vKq', title: '库区', width: 150, templet: '#vKq'},
                    {field: 'vHw', title: '货位编码', width: 150},
                    {field: 'gDepot', title: '所在仓库', width: 150},
                ]
            } else {
                bcSm = [
                    {width: "45", type: "numbers", fixed: "left"},
                    {field: 'sonCode', title: '子件编码', width: 200},
                    {field: 'sonName', title: '子件名称', width: 150},
                    {field: 'sonPurchaseNum', title: '子件采购总数', width: 150},//采购订单 子件信息
                    {field: 'sonNum', title: '子件差额数量', width: 150},//商品BOM信息
                    {field: 'sonPrice', title: '子件单价', width: 150},
                    {field: 'sonStoresNum', title: '子件上架数量', width: 150}
                ]
            }
            $.tablelist.init({
                elem: '#dhtable'
                , modalName: "采购报错列表"
                , data: noTable
                , cols: [bcSm]
                , page: false
                , height: 'full-' + ($('.north').height() + 140),
            });
            // table.reload('dhtable', {cols:[bcSm]});
        }

        // select 事件
        form.on('select(select_top)', function (data) {
            changeselect(data.value)
        });

        form.on('submit(btn-add)', function (data) {
            // var is_return = false//是否中断保存
            // fieldsList.map((v,i)=>{
            //     if(v.fieldFrontRequired){
            //         if(!$('#'+v.fields).val()){
            //              layer.msg(v.fieldName+'不能为空')
            //              is_return=true
            //         }
            //     }
            // })
            // if(is_return) return;
            var infoMap = {
                'activeFlow': $('#activeFlow').val(),
                'procInstId': $('#procInstId').val(),
                'effectStock': $('#effectStock').val(),
                nid,
                'errorExplain': $('#errorExplain').val(),
                'dispose': $('#dispose').val(),
                'disposeExplain': $('#disposeExplain').val(),
                'state': +vType
            }
            var res = table.cache.dhtable;
            $.post("/storage/purchasingerror/editpost", {
                'infoMap': JSON.stringify(infoMap),
                'infoItems': JSON.stringify(res)
            }, function (res) {
                layer.msg(res.msg);
                if (res.code == 0) {
                    //  window.location.href="/business/productbasis/edit?code="+$('#code').val();
                    setTimeout(function () {
                        window.location.reload();
                        // parent.layui.index.openTabsPage("/storage/purchasingerror/edit?nid="+res.data+'&vType='+vType, '采购报错单-处理');
                    }, 500)
                }
            });
            return false;
        });
        // window.getMoreAfter=
    })


    function getMoreAfter(fieldsList, fields, tindex, fieldName, fieldSearchType, isSearch, isLayer, datas) {//弹出框赋值回调
        console.log("datas", datas, tindex)
        if (fields == 'vGsMc') {
			table.cache.dhtable[tindex].vGsBm2 = datas.vGsBm
			table.cache.dhtable[tindex].vGsJc2 = datas.vGsJc
			table.reload('dhtable', table.cache.dhtable);
        } else if (fields == 'vKq') {
            table.cache.dhtable[tindex].vKq = datas.goodsArea
            table.cache.dhtable[tindex].vHw = datas.goodsAllocation
            table.cache.dhtable[tindex].gDepot = datas.warehouseAddress
            table.reload('dhtable', table.cache.dhtable);
        } else {
            table.cache.dhtable[tindex].vJyLx = datas.vJyLx
            table.cache.dhtable[tindex].salesReturnSum = datas.bPrice
            table.reload('dhtable', table.cache.dhtable);
        }

    }


</script>
</body>
</html>